import {useSelector,useDispatch} from 'react-redux';
import {Button} from 'antd'
import addNum from '@/store/addNum'

const View = () =>{
    const dispatch = useDispatch();
    const {num} = useSelector((state:RootState) => ({num:state.handlernum.num}))
    const {arr} = useSelector((state:RootState) => ({arr:state.handlerarr.arr}))


    const addOne = () =>{
        dispatch({type:'add2'});
    }

    const asyncAddOne = () =>{
        dispatch(addNum.asyncActions.asyncAdd)
    }

    const addFive = () =>{
        dispatch({type:'add',val:5});
    }


    const hadlerArr = () =>{
        let val = (arr[arr.length] % 2 == 0) ? arr[arr.length - 1] + 1 : arr[arr.length - 1] + 2
        dispatch({type:'arrpush',val});
    }



    return (
        <div>
            Page1
            <br />
            {num}
            <br />
            <Button type="primary" onClick={addOne}>点击++</Button>
            <Button type="primary" onClick={asyncAddOne}>异步点击++</Button>
            <Button type="primary" onClick={addFive}>点击+5</Button>
            <hr />
            {arr}
            <Button type="primary" onClick={hadlerArr}>点击添加一个数据</Button>
        </div>
    )
}

export default View